package com.hb.sq3d.vos;

import android.graphics.PointF;

import java.util.List;

public class LineArg {
    public int ID;
    public int style;
    public int colour;
    public float[] C;// c0,c1,c2,c3
    public float start;
    public float end;

    public List<PointF> points;

    public LineArg() {}

    public LineArg(int ID, int style, int colour, float[] C, float start, float end) {
        this.ID = ID;
        this.style = style;
        this.colour = colour;
        this.C = C;
        this.start = start;
        this.end = end;
    }

    public LineArg(int ID, int style, int colour, List<PointF> points) {
        this.ID = ID;
        this.style = style;
        this.colour = colour;
        this.points = points;
    }

    public static class JNIData {
        public int[] ids;
        public int[] styles;
        public int[] colours;

        public boolean[] isPointsDatas;

        public float[][] Cs;
        public float[] starts;
        public float[] ends;

        public int[] linePointsValuesNums;
        public float[][] allPointsValues;
    }

    public static JNIData getJNIDataFromLines(List<LineArg> lineArgs) {
        int N = lineArgs.size();
        JNIData jniLineArgs = new JNIData();
        jniLineArgs.ids = new int[N];
        jniLineArgs.styles = new int[N];
        jniLineArgs.colours = new int[N];
        jniLineArgs.isPointsDatas = new boolean[N];
        jniLineArgs.Cs = new float[N][4];
        jniLineArgs.starts = new float[N];
        jniLineArgs.ends = new float[N];
        jniLineArgs.linePointsValuesNums = new int[N];
        jniLineArgs.allPointsValues = new float[N][1000];

        for (int i = 0; i < lineArgs.size(); i++) {
            LineArg line = lineArgs.get(i);
            jniLineArgs.ids[i] = line.ID;
            jniLineArgs.styles[i] = line.style;
            jniLineArgs.colours[i] = line.colour;

            boolean usingPoints = line.points != null;
            jniLineArgs.isPointsDatas[i] = usingPoints;

            if (!usingPoints) {
                jniLineArgs.Cs[i] = line.C;
                jniLineArgs.starts[i] = line.start;
                jniLineArgs.ends[i] = line.end;

                jniLineArgs.linePointsValuesNums[i] = 0;
                jniLineArgs.allPointsValues[i] = new float[1];
            } else {
                jniLineArgs.Cs[i] = new float[1];
                jniLineArgs.starts[i] = 0;
                jniLineArgs.ends[i] = 0;

                int m = -1;
                int valuesNum = line.points.size() * 2;
                jniLineArgs.linePointsValuesNums[i] = valuesNum;
                for (int k = 0; k < line.points.size(); k++) {
                    PointF p = line.points.get(k);
                    jniLineArgs.allPointsValues[i][++m] = p.x;
                    jniLineArgs.allPointsValues[i][++m] = p.y;
                }
            }
        }
        return jniLineArgs;
    }
};
